<template>
    <div class="sidebar">
        <el-menu class="sidebar-el-menu" :default-active="onRoutes" :collapse="collapse" background-color="#324157"
            text-color="#bfcbd9" active-text-color="#20a0ff" unique-opened router>
            <template v-for="item in items">
                <template v-if="item.subs">
                    <el-submenu :index="item.index" :key="item.index">
                        <template slot="title">
                            <i :class="item.icon"></i><span slot="title">{{ item.title }}</span>
                        </template>
                        <el-menu-item v-for="(subItem,i) in item.subs" :key="i" :index="subItem.index">
                            {{ subItem.title }}
                        </el-menu-item>
                    </el-submenu>
                </template>
                <template v-else>
                    <el-menu-item :index="item.index" :key="item.index">
                        <i :class="item.icon"></i><span slot="title">{{ item.title }}</span>
                    </el-menu-item>
                </template>
            </template>
        </el-menu>
    </div>
</template>

<script>
    import bus from '../common/bus';
    export default {
        props:{
            mes:{
                required:true
            }
        },
        data() {
            return {
                collapse: false,
                /*items: [
                    {
                        icon: 'el-icon-setting',
                        index: 'dashboard',
                        title: '系统首页'
                    },
                    {
                        icon: 'el-icon-tickets',
                        index: 'table',
                        title: '基础表格'
                    },
                    {
                        icon: 'el-icon-message',
                        index: 'tabs',
                        title: 'tab选项卡'
                    },
                    {
                        icon: 'el-icon-date',
                        index: '3',
                        title: '表单相关',
                        subs: [
                            {
                                index: 'form',
                                title: '基本表单'
                            },
                            {
                                index: 'editor',
                                title: '富文本编辑器'
                            },
                            {
                                index: 'markdown',
                                title: 'markdown编辑器'
                            },
                            {
                                index: 'upload',
                                title: '文件上传'
                            }
                        ]
                    },
                    {
                        icon: 'el-icon-star-on',
                        index: 'charts',
                        title: 'schart图表'
                    },
                    {
                        icon: 'el-icon-rank',
                        index: 'drag',
                        title: '拖拽列表'
                    },
                    {
                        icon: 'el-icon-warning',
                        index: 'permission',
                        title: '权限测试'
                    },
                    {
                        icon: 'el-icon-error',
                        index: '404',
                        title: '404页面'
                    }
                ],*/
                items: [
                    {
                        icon: 'el-icon-setting',
                        index: '1',
                        title: '代理商管理',
                        subs: [
                            {
                                index: 'daili_shenhe',
                                title: '代理商信息'
                            },
                            {
                                index: 'daili_noshenhe',
                                title: '代理商信息(不需审核)'
                            },
                            {
                                index: 'daili_zhanghaojuese',
                                title: '代理商账户角色'
                            },
                            {
                                index: 'daili_dengluzhanghao',
                                title: '代理商登录账号'
                            }
                        ]
                    },
                    {
                        icon: 'el-icon-setting',
                        index: '2',
                        title: '集团管理',
                        subs: [
                            {
                                index: 'jituan_shenhe',
                                title: '集团信息'
                            },
                            {
                                index: 'jituan_noshenhe',
                                title: '集团信息(不需要审核)'
                            },
                            {
                                index: 'jituan_zhjs',
                                title: '集团账户角色'
                            },
                            {
                                index: 'jituan_dlzh',
                                title: '集团登录账号'
                            }
                        ]
                    },
                    {
                        icon: 'el-icon-setting',
                        index: '3',
                        title: '品牌管理',
                        subs: [
                            {
                                index: 'pinpai_shenhe',
                                title: '品牌信息'
                            },
                            {
                                index: 'pinpai_noshenhe',
                                title: '品牌信息(不需要审核)'
                            },
                            {
                                index: 'pinpai_zhjs',
                                title: '品牌账号角色'
                            },
                            {
                                index: 'pinpai_dlzh',
                                title: '品牌登录账号'
                            }
                        ]
                    },
                    {
                        icon: 'el-icon-setting',
                        index: '4',
                        title: '门店管理',
                        subs: [
                            {
                                index: 'mendian_shenhe',
                                title: '门店信息'
                            },
                            {
                                index: 'mendian_noshenhe',
                                title: '门店信息(不需要审核)'
                            },
                            {
                                index: 'mendian_zhjs',
                                title: '门店账号角色'
                            },
                            {
                                index: 'mendian_dlzh',
                                title: '门店登录账号'
                            }
                        ]
                    },
                    {
                        icon: 'el-icon-setting',
                        index: '5',
                        title: '基础设置',
                        subs: [
                            {
                                index: 'zuzhicengji',
                                title: '组织层级设置'
                            },
                            {
                                index: 'zuzhishenhe',
                                title: '组织审核设置'
                            },
                            {
                                index: 'mendianleixing',
                                title: '门店类型维护'
                            }
                        ]
                    },
                ],
                item1: [
                    {
                        icon: 'el-icon-setting',
                        index: '1',
                        title: '代理商管理',
                        subs: [
                            {
                                index: 'daili_shenhe',
                                title: '代理商信息'
                            },
                            {
                                index: 'daili_noshenhe',
                                title: '代理商信息(不需审核)'
                            },
                            {
                                index: 'daili_zhanghaojuese',
                                title: '代理商账户角色'
                            },
                            {
                                index: 'daili_dengluzhanghao',
                                title: '代理商登录账号'
                            }
                        ]
                    },
                    {
                        icon: 'el-icon-setting',
                        index: '2',
                        title: '集团管理',
                        subs: [
                            {
                                index: 'jituan_shenhe',
                                title: '集团信息'
                            },
                            {
                                index: 'jituan_noshenhe',
                                title: '集团信息(不需要审核)'
                            },
                            {
                                index: 'jituan_zhjs',
                                title: '集团账户角色'
                            },
                            {
                                index: 'jituan_dlzh',
                                title: '集团登录账号'
                            }
                        ]
                    },
                    {
                        icon: 'el-icon-setting',
                        index: '3',
                        title: '品牌管理',
                        subs: [
                            {
                                index: 'pinpai_shenhe',
                                title: '品牌信息'
                            },
                            {
                                index: 'pinpai_noshenhe',
                                title: '品牌信息(不需要审核)'
                            },
                            {
                                index: 'pinpai_zhjs',
                                title: '品牌账号角色'
                            },
                            {
                                index: 'pinpai_dlzh',
                                title: '品牌登录账号'
                            }
                        ]
                    },
                    {
                        icon: 'el-icon-setting',
                        index: '4',
                        title: '门店管理',
                        subs: [
                            {
                                index: 'mendian_shenhe',
                                title: '门店信息'
                            },
                            {
                                index: 'mendian_noshenhe',
                                title: '门店信息(不需要审核)'
                            },
                            {
                                index: 'mendian_zhjs',
                                title: '门店账号角色'
                            },
                            {
                                index: 'mendian_dlzh',
                                title: '门店登录账号'
                            }
                        ]
                    },
                    {
                        icon: 'el-icon-setting',
                        index: '5',
                        title: '基础设置',
                        subs: [
                            {
                                index: 'zuzhicengji',
                                title: '组织层级设置'
                            },
                            {
                                index: 'zuzhishenhe',
                                title: '组织审核设置'
                            },
                            {
                                index: 'mendianleixing',
                                title: '门店类型维护'
                            }
                        ]
                    },
                ],
                item2: [
                    {
                        icon: 'el-icon-setting',
                        index: '1',
                        title: '商品信息',
                        subs: [
                            {
                                index: 'yuanliao',
                                title: '原料信息'
                            },
                            {
                                index: 'shangpin',
                                title: '商品信息'
                            },
                            {
                                index: 'markdown',
                                title: '套餐信息'
                            }
                        ]
                    },
                    {
                        icon: 'el-icon-setting',
                        index: '2',
                        title: '商品参数',
                        subs: [
                            {
                                index: 'form',
                                title: '原料分类'
                            },
                            {
                                index: 'editor',
                                title: '商品分类'
                            },
                            {
                                index: 'markdown',
                                title: '套餐分类'
                            },
                            {
                                index: 'markdown',
                                title: '商品属性'
                            },
                            {
                                index: 'markdown',
                                title: '商品做法'
                            },
                            {
                                index: 'markdown',
                                title: '商品口味'
                            },
                            {
                                index: 'markdown',
                                title: '商品标签'
                            },
                            {
                                index: 'markdown',
                                title: '备注配置'
                            }
                        ]
                    }
                ]
            }
        },
        computed:{
            onRoutes(){
                return this.$route.path.replace('/','');
            }
        },
        created(){
            // 通过 Event Bus 进行组件间通信，来折叠侧边栏
            bus.$on('collapse', msg => {
                this.collapse = msg;
            })
        },
        watch:{
            mes:function (val) {
                switch (val) {
                    case '1':
                        this.items = this.item1
                        break;
                    case '2':
                        this.items = this.item2
                        break;
                    case '3':
                        this.items = this.item1
                        break;
                    case '4':
                        this.items = this.item1
                        break;
                    case '5':
                        this.items = this.item1
                        break;
                    case '6':
                        this.items = this.item1
                        break;
                    case '7':
                        this.items = this.item1
                        break;
                    case '8':
                        this.items = this.item1
                        break;
                    case '9':
                        this.items = this.item1
                        break;
                    case '10':
                        this.items = this.item1
                        break;
                }
            }
        }
    }
</script>

<style scoped>
    .sidebar{
        display: block;
        position: absolute;
        left: 0;
        top: 70px;
        bottom:0;
        overflow-y: scroll;
    }
    .sidebar::-webkit-scrollbar{
        width: 0;
    }
    .sidebar-el-menu:not(.el-menu--collapse){
        width: 250px;
    }
    .sidebar > ul {
        height:100%;
    }
</style>
